﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.ErrorCode;
using Traceability.Read.Api.Application.Command;
using Traceability.Read.Api.Dto;

namespace Traceability.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MainController : ControllerBase
    {

        private readonly IMediator mediator;

        public MainController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 登录方法
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<LoginDto>> Login([FromQuery] LoginCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 反添图片功能
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<ImagerDto>>> GetImage([FromQuery] GetImageCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 显示养殖信息操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<CultivationDto>>> GetCultivation([FromQuery] GetCultivationCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 查询免疫信息操作
        /// </summary>
        /// <param name="request"></param
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<ImmunityDto>>> GetImmunity([FromQuery] GetImmunityCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 查询养殖企业操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<EnterprisesDto>>> GetEnterprises([FromQuery] GetEnterprisesCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 显示屠宰信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<SlaughterDto>>> GetSlaughter([FromQuery] GetSlaughterCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 供应商操作
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<VendorDto>>> GetVendor([FromQuery] GetVendorCommand request)
        {
            try
            {
                return mediator.Send(request);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
